import json

from apps.common.base.serializers import *
from apps.system.formRecord.models import *


class FormRecordBaseSerializer(BaseSerializer):
    class Meta:
        model = FormRecord
        fields = "__all__"


class FormRecordModelSerializer(BaseSerializer):
    formModel = serializers.SerializerMethodField()

    def get_formModel(self, obj):
        try:
            return {'id': obj.form.id, 'name': obj.form.name, 'key': obj.form.key}
        except:
            return {}

    contentList = serializers.SerializerMethodField()

    def get_contentList(self, obj):
        try:
            return json.loads(obj.content)
        except:
            return []

    class Meta:
        model = FormRecord
        fields = "__all__"
